using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Deepcode.Flux.Core.Data;

namespace Deepcode.Flux.Core.Systems.Security
{
	/// <summary>
	/// Manager class for the administration group permissions table
	/// </summary>
	public class AdminGroupPermissions : Deepcode.Flux.Core.Data.BaseManager
	{
		#region Constructors
		public AdminGroupPermissions() : base() { }
		public AdminGroupPermissions(SqlConnection CurrentConnection) : base(CurrentConnection) { }
		public AdminGroupPermissions(SqlConnection CurrentConnection, SqlTransaction CurrentTransaction) : base(CurrentConnection, CurrentTransaction) { }
		#endregion
		#region Data Retrieval
		/// <summary>
		/// Retrieves the administration group permission records associated with the group specified
		/// </summary>
		/// <param name="GroupID"></param>
		/// <returns></returns>
		public AdminGroupPermission[] GetForGroup(int GroupID)
		{
			DataTable t = new DataTable();
			List<AdminGroupPermission> results = new List<AdminGroupPermission>();

			EstablishConnection();
			SqlDataAdapter da = this.CreateDataAdapter("coreAdminGroupPermissionGetForGroup");
			da.SelectCommand.Parameters.Add(SQLUtility.ParameterIn("@groupid", SqlDbType.Int, 4, GroupID));
			da.Fill(t);
			ReleaseConnection();

			foreach (DataRow r in t.Rows)
				results.Add(new AdminGroupPermission(r));

			return results.ToArray();
		}
		#endregion
	}
}